<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<%@ taglib uri="/permission" prefix="pe" %>

<jsp:include page="../../include/top.jsp"/>
<div class="main_body">
    <div class="span9 page_message">
        <section id="contents">
            <ul class="tab-nav nav">
                <li class="current"><a href="">团单列表<span class="arrow fa fa-sort-up"></span></a></li>
                <li><a href="javascript:toAdd()">团单添加/修改<span class="arrow fa fa-sort-up"></span></a></li>
                <li><a href="javascript:test();void(0);">导入人员数据<span class="arrow fa fa-sort-up"></span></a></li>
                <li><a href="javascript:exportOrder();void(0);">导出人员数据<span class="arrow fa fa-sort-up"></span></a></li>
                <li><a href="javascript:multiDel();void(0);">删除<span class="arrow fa fa-sort-up"></span></a></li>
                <li><a href="javascript:groupOrderPay();void(0);">付款信息<span class="arrow fa fa-sort-up"></span></a></li>
                <li><a href="javascript:printBarcode();void(0);">打印条码<span class="arrow fa fa-sort-up"></span></a></li>
                <li><a href="${BasePath}/jsp/files/order_model.xls">Exl模板下载<span class="arrow fa fa-sort-up"></span></a></li>
                <li><a href="javascript:toRemark();void(0);">备注<span class="arrow fa fa-sort-up"></span></a></li>

            </ul>
            <p class="normal_tips" style="display:none"><b class="fa fa-info-circle"></b></p>

            <div class="table-bar">
                <div class="fl">
                    <div class="tools">

                    </div>
                    <div class="search-form fr cf">
                        <form id="myForm" name="myForm" action="${BasePath}/order/groupOrder/list?${PublicParams}" method="post">
                            团体名称：<input type="text" class="txt100" name="groupName" value="${groupName}"/>
                            联系人：<input type="text" class="txt100" name="contactName" value="${contactName}"/>
                            <input type="submit" value="查询" class="btn btn-success " style="margin-top: -10px"/>
                            <input type="hidden" name="start" id="start" value="${start }"/>
                            <input type="hidden" name="limit" id="limit" value="${limit }"/>
                        </form>
                    </div>
                </div>
            </div>
            <div class="data-table">
                <div class="table-striped">
                    <table cellspacing="1">
                        <thead>
                        <tr>
                            <th class="row-selected row-selected">
                                <input type="checkbox" id="checkAll" class="check-all regular-checkbox"><label for="checkAll"></label>
                            </th>
                            <th>ID</th>
                            <th>团单名称</th>
                            <th>负责人</th>
                            <th>公司名称</th>
                            <th>联系人</th>
                            <th>地址</th>
                            <th>电话</th>
                            <th>手机</th>
                            <th>Email</th>
                            <th>有效期</th>
                            <th>应收金额</th>
                            <th>已付金额</th>
                            <th>负责人</th>
                            <th>创建时间</th>
                            <th>备注</th>
                            <th>产品关键字</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach items="${list}" var="bean">
                            <tr>
                                <td><input type="checkbox" id="check_${bean.id}" name="ids[]" value="${bean.id}" class="ids regular-checkbox"><label for="check_${bean.id}"></label></td>
                                <td class="id">${bean.id}</td>
                                <td><a href="${BasePath}/order/order/list?${PublicParams}&groupOrderId=${bean.id}" target="_blank">${bean.groupName}</a></td>
                                <td>${bean.director}</td>
                                <td>${bean.companyName}</td>
                                <td>${bean.contactName}</td>
                                <td>${bean.address}</td>
                                <td>${bean.phone}</td>
                                <td>${bean.mobile}</td>
                                <td>${bean.email}</td>
                                <td>
                                    <c:if test="${bean.startDate>0}"><script>formatDate(${bean.startDate});</script></c:if>
                                    -
                                    <c:if test="${bean.endDate>0}"><script>formatDate(${bean.endDate});</script></c:if>
                                </td>
                                <td><input type="button" value="显示" class="btn-small btn-primary" onclick="showAmount(${bean.id})" id="btnShow${bean.id}" style="margin-top: -10px"/></td>
                                <td><a href="${BasePath}/order/groupOrderPay/list?${PublicParams}&idGroupOrder=${bean.id}" title="查看付款信息">${bean.paidAmount}</a></td>
                                <td>${bean.director}</td>
                                <td><script>formatDate(${bean.createTime});</script></td>
                                <td>${bean.remark}</td>
                                <td>${bean.productKeyword}</td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                    <div class="page" id="pager"></div>
                    <script type="text/javascript">
                        var sign = 0;
                        window.onload = function () {
                            PAGER.initPager('${start}', '${total}', '${limit}', 8, 'pager', getData);
                        }
                        function getData(currentPage, pageSize) {
                            if (sign > 0) {
                                $("#start").val(currentPage);
                                $("#limit").val(pageSize);
                                $("#myForm").submit();
                            }
                            sign = 1;
                        }
                    </script>
                </div>
            </div>
        </section>
    </div>
</div>
<jsp:include page="../../include/bottom.jsp"/>
<script type="application/javascript">
    function test() {
        var bodyDetailArray = new Array();
        $("input[name='ids[]']:checked").each(function () {
            var txt = $(this).val();
            bodyDetailArray.push(txt);
        });
        if (bodyDetailArray.length == 0) {
            layer.msg('请选择团体！', {icon: 5});
            return false;
        } else if (bodyDetailArray.length > 1) {
            layer.msg('请选择一条记录进行操作！', {icon: 5});
            return false;
        }
        $("#groupId").val(bodyDetailArray);
        layer.open({
            type: 1,
            title: '上传人员名单',
            shadeClose: true,
            shade: false,
            maxmin: true, //开启最大化最小化按钮
            area: ['893px', '600px'],
            content: $('#aaaa')
        });
    }
    function exportOrder() {
        var bodyDetailArray = new Array();
        $("input[name='ids[]']:checked").each(function () {
            var txt = $(this).val();
            bodyDetailArray.push(txt);
        });
        if (bodyDetailArray.length == 0) {
            layer.msg('请选择团体！', {icon: 5});
            return false;
        } else if (bodyDetailArray.length > 1) {
            layer.msg('请选择一条记录进行操作！', {icon: 5});
            return false;
        }
        window.location = "${BasePath}/order/groupOrder/exportGroupOrder?id=" + bodyDetailArray;
    }

    function checkForm() {
        var file = $("#file").val();
        if (file == "") {
            layer.msg('请选择文件！', {icon: 5});
            return false;
        }
        $('#uploadForm').ajaxSubmit(function (data) {
            if (data.errno == 1) {
                layer.alert(data.errdesc);
            } else {
                layer.msg("上传成功！");
            }
        });
    }

    function toAdd() {
        var idArray = new Array();
        $("input[name='ids[]']:checked").each(function () {
            var txt = $(this).val();
            idArray.push(txt);
        });
        //新增
        if (idArray.length == 0) {
            window.location.href = " ${BasePath}/order/groupOrder/toAdd?${PublicParams}";
        } else if (idArray.length == 1) {
            window.location.href = " ${BasePath}/order/groupOrder/toEdit?${PublicParams}&id=" + idArray;
        } else {
            layer.msg('请选择一条记录进行操作！', {icon: 5});
            return false;
        }
    }
    function multiDel() {
        var idArray = new Array();
        $("input[name='ids[]']:checked").each(function () {
            var txt = $(this).val();
            idArray.push(txt);
        });
        if (idArray.length == 0) {
            layer.msg('请选择一条记录进行操作！', {icon: 5});
            return false;
        } else {
            layer.msg('你确定要删除吗？', {
                time: 0 //不自动关闭
                , btn: ['确定', '取消']
                , yes: function (index) {
                    layer.close(index);
                    $.getJSON("${BasePath}/order/groupOrder/multiDel?ids=" + idArray.toString(), function (data) {
                        if (data.errno == 0) {
                            layer.msg("操作成功！");
                            window.location.reload();
                        } else {
                            layer.msg(data.errdesc, {icon: 5});
                        }
                    });
                }
            });
        }
    }
    function showAmount(gid) {
        $.getJSON("${BasePath}/order/groupOrder/showAmount?id=" + gid, function (data) {
            if (data.errno == 0) {
                $("#btnShow" + gid).parent().html(data.amount);
            } else {
                layer.msg("查询失败：" +data.errdesc, {icon: 5});
            }
        });
    }
    function printBarcode() {
        var idArray = new Array();
        $("input[name='ids[]']:checked").each(function () {
            var txt = $(this).val();
            idArray.push(txt);
        });
        if (idArray.length == 0) {
            layer.msg('请选择一条记录进行操作！', {icon: 5});
            return false;
        } else {
            layer.open({
                type: 2,
                offset: '100px',
                area: ['800px', '800px'],
                fix: false, //不固定
                maxmin: true,
                content: '${BasePath}/order/order/toPrintBarcode?groupOrderId=' + idArray[0]
            });
        }
    }
    function groupOrderPay() {
        var idArray = new Array();
        $("input[name='ids[]']:checked").each(function () {
            var txt = $(this).val();
            idArray.push(txt);
        });
        if (idArray.length == 0) {
            layer.msg('请选择一条记录进行操作！', {icon: 5});
            return false;
        } else {
            layer.open({
                type: 2,
                offset: '100px',
                area: ['800px', '800px'],
                fix: false, //不固定
                maxmin: true,
                content: '${BasePath}/order/groupOrderPay/list?idGroupOrder=' + idArray[0]
            });
        }
    }
    function toRemark(){
        var idArray = new Array();
        $("input[name='ids[]']:checked").each(function () {
            var txt = $(this).val();
            idArray.push(txt);
        });
        if (idArray.length == 0) {
            layer.msg('请选择一条记录进行操作！', {icon: 5});
            return false;
        } else {
            layer.open({
                type: 2,
                offset: '100px',
                area: ['400px', '200px'],
                fix: false, //不固定
                maxmin: true,
                content: '${BasePath}/order/groupOrder/toRemark?id=' + idArray[0]
            });
        }
    }
</script>
<div id="aaaa" style="display: none">
    <form id="uploadForm" name="uploadForm" action="${BasePath}/order/groupOrder/uploadExcel" method="post" enctype="multipart/form-data">
        <table id="edittable" style="width:100%;" align="center">
            <tr>
                <td colspan="4" class="column_head" style="font-size:14px;font-weight:bold;height:20px;">
                    上传人员名单
                    <input type="hidden" name="groupId" id="groupId" value=""/>
                </td>
            </tr>
            <tr>
                <td class="column_name">
                    请上传人员名单
                </td>
                <td class="column_input">
                    <input type="file" name="file" id="file" placeholder="请上传人员名单">
                </td>
                <td class="column_input">
                    <input type="button" onclick="checkForm()" value="上传">
                </td>
            </tr>
        </table>
    </form>
</div>